/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.news.service.mapper;

import co.yixiang.common.mapper.CoreMapper;
import co.yixiang.modules.news.domain.YxUserNews;
import co.yixiang.modules.news.service.vo.YxUserNewsVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author ycl
* @date 2020-08-13
*/
@Repository
public interface YxUserNewsMapper extends CoreMapper<YxUserNews> {


    @Select("select yn.* , yun.id as yid , yun.is_read as isRead from yx_user_news yun , yx_news yn where yun.news_id = yn.id  and user_id = #{uid}  order by create_time desc")
    Page<YxUserNewsVo> getNewsByUserId(@Param("page") Page page, @Param("uid") Long uid, @Param("type") Integer type);

    @Select("select yn.* , yun.id as yid from yx_user_news yun , yx_news yn where yun.news_id = yn.id and user_id = #{uid} and type = #{type} and is_read = 0 ORDER BY yn.create_time DESC LIMIT 1 ")
    YxUserNewsVo readRemind(@Param("uid") Long uid, @Param("type") Integer type);

    @Update("update yx_user_news set is_read=1 where news_id=#{id} and user_id=#{uid}")
    void updateIsRead(@Param("id") Integer id, @Param("uid") Long uid);
}
